import '../repository/rest_client.dart';
import '../repository/token_repository.dart';
import 'usecase.dart';

class GetTokenUseCase implements UseCase<Future<String>, NoParams> {
  final TokenRepository _repository;
  final RestClient client;

  GetTokenUseCase(this._repository, this.client);

  @override
  Future<String> call(NoParams params) async {
    final token = await _repository.getToken();
    client.setAuthorization(token);
    return token;
  }
}

class SetTokenUseCase extends UseCase<void, String> {
  final TokenRepository _repository;
  final RestClient client;

  SetTokenUseCase(this._repository, this.client);

  @override
  Future<void> call(String params) async {
    client.setAuthorization(params);
    await _repository.setToken(params);
  }
}

class UpdateAjaxClientInfoUseCase extends UseCase<void, String> {
  final RestClient client;

  UpdateAjaxClientInfoUseCase(this.client);

  @override
  Future<void> call(String params) async {
    client.setHostEnv(params.split(',')[0], int.parse(params.split(',')[1]));
  }
}
